
package com.hlkj.pay.infrastructure.model.merchant;

import java.util.List;

import org.springframework.util.StringUtils;

import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName;
import com.hlkj.framework.common.util.json.JsonUtils;
import com.hlkj.framework.mybatis.core.dataobject.BaseDO;
import com.hlkj.pay.enums.MerchantEnum;

import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;

/**
 * 商户app配置表
 * 
 * @TableName t_merchant_app_channel
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
@EqualsAndHashCode(callSuper = true)
@TableName("t_merchant_app_channel")
public class MerchantAppChannelDO extends BaseDO {

    /**
     * 通道编码
     */
    @Schema(description = "通道编码")
    private String code;

    /**
     * @see MerchantEnum.APP_CHANNEL_TYPE
     */
    @Schema(description = "类型 1:特约商户 2:普通商户")
    private Integer type;

    /**
     * 商户商户号
     */
    @Schema(description = "商户商户号")
    private String sn;

    /**
     * 商户商户号
     */
    @Schema(description = "子商户号")
    private String subMchId;

    /**
     * 商户商户号
     */
    @Schema(description = "appid")
    private String appId;

    /**
     * 默认服务商
     */
    @Schema(description = "默认服务商")
    private String providerCode;

    /**
     * 默认通道
     */
    @Schema(description = "默认通道")
    private String channelCode;

    /**
     * 通道配置
     */
    @Schema(description = "通道配置")
    private String appConfigJson;

    /**
     * 是否启用：0-关闭；1-开启；
     */
    @Schema(description = "是否启用：0-关闭；1-开启；")
    private Integer status;

    /**
     * 是否轮询
     * @see com.hlkj.pay.enums.CommonEnum.YES_NO_TYPE
     */
    @Schema(description = "是否轮询：1-是；0-否；")
    private Integer limitRouter;

    /**
     * 权重
     */
    @Schema(description = "权重")
    private Integer weight;

    /**
     * 备注
     */
    @Schema(description = "备注")
    private String remark;

    /**
     * 进件id
     */
    @Schema(description = "进件id")
    private Long accessId;

    /**
     * 进件id
     */
    @Schema(description = "类型 1 进件 2 报备")
    private Integer accessType;

    /**
     * 通道配置
     */
    @Schema(description = "通道配置")
    @TableField(exist = false)
    private Object appConfig;

    /**
     */
    @Schema(description = "分账类型 ，0或空=无分账，1=实时分账，2=延时分账，3=商户 预设默认分账")
    private Integer fundProcessType;

    /**
     * 通道已选的支付方式
     */
    @Schema(description = "通道已选的支付方式")
    @TableField(exist = false)
    private List<String> payWayCodes;

    /**
     * 通道已选的支付方式
     */
    @Schema(description = "通道已选的支付方式")
    private String payWayCode;



    public Object getAppConfig() {
        if (appConfig != null) {
            return appConfig;
        }
        if (StringUtils.hasText(appConfigJson)) {
            setAppConfig(JsonUtils.parseObject(appConfigJson, Object.class));
        }
        return appConfig;
    }



    public List<String> getPayWayCodes() {
        if (this.payWayCodes != null) {
            return this.payWayCodes;
        }
        if (StringUtils.hasText(payWayCode)) {
            setPayWayCodes(JsonUtils.parseArray(payWayCode, String.class));
        }

        return this.payWayCodes;
    }
}
